#include<iostream>
using namespace std;
class counter {
protected:
	int value;
public:
	counter(int v):value(v){}
	void increment() {
		value++;
	}
};
class cycle_counter :public counter {
private:
	int minValue;
	int maxValue;
public:
	cycle_counter(int v, int min, int max) :counter(v),minValue(min),maxValue(max) {

	}
	int increment() {
		value++;
		if (value == maxValue) {
			value = minValue;
			return 1;
		}
		return 0;
	}
	void print() {
		cout << value;
	}
};
class _clock{
private:
	cycle_counter hour;
	cycle_counter minute;
	cycle_counter second;
public:
	_clock(int h, int m, int s) :hour(h, 0, 24), minute(m, 0, 60), second(s, 0, 60) {}
	void _time(int s) {
		int a, b;
		while (s) {
			a = second.increment();
			if (a) {
				b = minute.increment();
				if (b) {
					hour.increment();
				}
			}
			s--;
		}
	}
	void time_print() {
		hour.print();
		cout << ':';
		minute.print();
		cout << ':';
		second.print();
		cout << endl;
	}
};
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int hour, minute, second;
		cin >> hour >> minute >> second;
		_clock c(hour, minute, second);
		int now;
		cin >> now;
		c._time(now);
		c.time_print();
	}
	return 0;
}